/*
 * @Author: liuxiao
 * @Date: 2023-11-25 19:28:33
 * @Last Modified by: liuxiao
 * @Last Modified time: 2023-12-05 12:09:18
 * @ps:数据库相关配置，创建sequelize，测试连接是否正常
 */

//导入sequelize
const { Sequelize } = require('sequelize')

const {
  MYSQL_HOST,
  MYSQL_PORT,
  MYSQL_USER,
  MYSQL_PWD,
  MYSQL_DB
} = require('../config/config.default')
//TODO，这里可以优化，从process.env中解构
//const { MYSQL_HOST, MYSQL_PORT, MYSQL_USER, MYSQL_PWD, MYSQL_DB } = process.env

const seq = new Sequelize(MYSQL_DB, MYSQL_USER, MYSQL_PWD, {
  host: MYSQL_HOST,
  dialect: 'mysql'
})

seq
  .authenticate()
  .then(() => {
    console.log('数据库连接成功')
  })
  .catch((err) => {
    console.error('数据库连接失败:')
  })

module.exports = seq
